package com.lineage.server.model.skill.skillmode;

import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Magic;
import com.lineage.server.serverpackets.S_SkillHaste;
import com.lineage.server.serverpackets.ServerBasePacket;

public class HASTE extends SkillMode {
  public int start(L1PcInstance srcpc, L1Character cha, L1Magic magic, int integer) throws Exception {
    int dmg = 0;
    if (cha.getMoveSpeed() != 2) {
      if (cha instanceof L1PcInstance) {
        L1PcInstance pc = (L1PcInstance)cha;
        if (pc.getHasteItemEquipped() > 0)
          return 0; 
        pc.setDrink(false);
        pc.sendPackets((ServerBasePacket)new S_SkillHaste(pc.getId(), 1, integer));
      } 
      cha.setSkillEffect(43, integer * 1000);
      cha.broadcastPacketAll((ServerBasePacket)new S_SkillHaste(cha.getId(), 1, 0));
      cha.setMoveSpeed(1);
    } else {
      int skillNum = 0;
      if (cha.hasSkillEffect(29)) {
        skillNum = 29;
      } else if (cha.hasSkillEffect(76)) {
        skillNum = 76;
      } else if (cha.hasSkillEffect(152)) {
        skillNum = 152;
      } 
      if (skillNum != 0) {
        cha.removeSkillEffect(skillNum);
        cha.removeSkillEffect(43);
        cha.setMoveSpeed(0);
        return 0;
      } 
    } 
    return 0;
  }
  
  public int start(L1NpcInstance npc, L1Character cha, L1Magic magic, int integer) throws Exception {
    int dmg = 0;
    if (cha.getMoveSpeed() != 2) {
      cha.setSkillEffect(43, integer * 1000);
      cha.broadcastPacketAll((ServerBasePacket)new S_SkillHaste(cha.getId(), 1, 0));
      cha.setMoveSpeed(1);
    } else {
      int skillNum = 0;
      if (cha.hasSkillEffect(29)) {
        skillNum = 29;
      } else if (cha.hasSkillEffect(76)) {
        skillNum = 76;
      } else if (cha.hasSkillEffect(152)) {
        skillNum = 152;
      } 
      if (skillNum != 0) {
        cha.removeSkillEffect(skillNum);
        cha.removeSkillEffect(43);
        cha.setMoveSpeed(0);
        return 0;
      } 
    } 
    return 0;
  }
  
  public void start(L1PcInstance srcpc, Object obj) throws Exception {}
  
  public void stop(L1Character cha) throws Exception {
    if (cha instanceof L1PcInstance) {
      L1PcInstance pc = (L1PcInstance)cha;
      pc.sendPackets((ServerBasePacket)new S_SkillHaste(pc.getId(), 0, 0));
    } 
    cha.broadcastPacketAll((ServerBasePacket)new S_SkillHaste(cha.getId(), 0, 0));
    cha.setMoveSpeed(0);
  }
}
